package com.turnengine.client.local.faction.bean;

import com.turnengine.client.local.faction.enums.FactionUnited;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Faction.
 */
public class Faction implements IFaction, Comparable<IFaction> {

	/** The id. */
	private int id = -1;
	/** The name. */
	private String name = "";
	/** The password. */
	private String password = "";
	/** The united. */
	private FactionUnited united = FactionUnited.DIVIDED;
	/** The player limit. */
	private int playerLimit = 0;

	/**
	 * Creates a new Faction.
	 */
	public Faction() {
	}

	/**
	 * Creates a new Faction.
	 * @param id the id
	 * @param name the name
	 * @param password the password
	 * @param united the united
	 * @param playerLimit the player limit
	 */
	public Faction(int id, String name, String password, FactionUnited united, int playerLimit) {
		setId(id);
		setName(name);
		setPassword(password);
		setUnited(united);
		setPlayerLimit(playerLimit);
	}

	/**
	 * Creates a new Faction.
	 * @param faction the faction
	 */
	public Faction(Faction faction) {
		setId(faction.getId());
		setName(faction.getName());
		setPassword(faction.getPassword());
		setUnited(faction.getUnited());
		setPlayerLimit(faction.getPlayerLimit());
	}

	/**
	 * Creates a new Faction.
	 * @param iFaction the i faction
	 */
	public Faction(IFaction iFaction) {
		setId(iFaction.getId());
		setName(iFaction.getName());
		setPassword(iFaction.getPassword());
		setUnited(iFaction.getUnited());
		setPlayerLimit(iFaction.getPlayerLimit());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the password.
	 * @return the password.
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Returns the united.
	 * @return the united.
	 */
	public FactionUnited getUnited() {
		return united;
	}

	/**
	 * Returns the player limit.
	 * @return the player limit.
	 */
	public int getPlayerLimit() {
		return playerLimit;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the password.
	 * @param password the password to set.
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * Sets the united.
	 * @param united the united to set.
	 */
	public void setUnited(FactionUnited united) {
		this.united = united;
	}

	/**
	 * Sets the player limit.
	 * @param playerLimit the player limit to set.
	 */
	public void setPlayerLimit(int playerLimit) {
		this.playerLimit = playerLimit;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(601, 37);
		hash.append(id);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Faction) {
			Faction compare = (Faction) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IFaction compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (name != null) {
			string.append("name", name);
		}
		if (password != null) {
			string.append("password", password);
		}
		if (united != null) {
			string.append("united", united);
		}
		string.append("playerLimit", playerLimit);
		return string.toString();
	}
}
